package com.xrui.hbase.filter;

import com.xrui.hbase.ColumnName;
import org.apache.hadoop.hbase.filter.Filter;

import java.io.IOException;
import java.io.Serializable;

/**
 * A column filter provides a means of filtering cells from a column on the server side.
 * <p>
 * <p>To make your jobs more efficient, you may use a ColumnFilter to specify that
 * certain cells from a column be filtered. The cells will be filtered on the server,
 * which reduces the amount of data that needs to be sent to the client.</p>
 * <p>
 * <p>ColumnFilters filter cells from a column, in contrast with RowFilters, which
 * filters rows from a table.</p>
 * <p>
 * <p>Classes extending ColumnFilter must implement the <code>hashCode</code> and
 * <code>equals</code> methods.</p>
 *
 * @see RowFilter
 * @see DataRequestBuilder.ColumnsDef#withFilter(ColumnFilter)
 */
public abstract class ColumnFilter implements Serializable {
    /**
     * Expresses the ColumnFilter in terms an equivalent HBase Filter.
     *
     * @param columnName The column this filter applies to.
     *                   //* @param context    The context.
     * @return An equivalent HBase Filter.
     * @throws IOException If there is an error.
     */
    public abstract Filter toHBaseFilter(ColumnName columnName/*, Context context*/)
        throws IOException;

    /**
     * An object available to ColumnFilters that can be used to help implement the
     * toHBaseFilter() method.
     */
    public abstract static class Context {
        /**
         * Converts a HBase column name to an HBase column name.
         *
         * @param columnName The name of a hbase column.
         * @return The name of the HBase column that stores the hbase column data.
         * @throws NoSuchColumnException If there is no such column in the hbase table.
         */
        //public abstract HBaseColumnName getHBaseColumnName(ColumnName columnName)
        //    throws NoSuchColumnException;
    }
}
